import { gql } from '@apollo/client';
import { withApollo, graphql } from '@apollo/client/react/hoc';
import { compose } from 'recompose';
import viewstateHoc from '@kuiper-components/viewstate-hoc';
import { TASK_CATEGORY_TYPES_MAP } from '../../../../common/constants';

export default compose(
	withApollo,
	graphql(
		gql`
			query($id: MongoID) {
				${TASK_CATEGORY_TYPES_MAP.weakness.map(
					type => `
						${type}Results: ResultNumbersMany(
							filter: {jobId: $id, taskType: ${type}},
							sort:_ID_DESC
							limit: 10
						) {
							_id
							taskId
							taskName
							target
							datetime
							taskType
							highWarnCount
							mediumWarnCount
							lowWarnCount
							warnCount
							normalNodeCount
							totalNodeCount
						}
					`
				)}
			}
		`,
		{
			options({ jobId }) {
				return {
					variables: { id: jobId },
				};
			},
		}
	),
	viewstateHoc()
);
